//
//  HomeSectionView.m
//  KTVShopProduct
//
//  Created by paeanSs on 2017/11/8.
//  Copyright © 2017年 paeanSs. All rights reserved.
//

#import "HomeSectionView.h"

@interface HomeSectionView ()

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *url_Image;

@end

@implementation HomeSectionView

- (instancetype)initWithTitle:(NSString *)title url_Image:(NSString *)url_Image{
    if (self = [super initWithFrame:CGRectMake(0, 0, KTScreenWidth, SECTION_HEIGHT)]) {
        self.title = title;
        self.url_Image = url_Image;
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews{
    self.backgroundColor = [UIColor whiteColor];
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
//    [self.titleLabel sizeToFit];
    [self addSubview:self.titleLabel];
    
    UIImage *currentImage = [UIImage imageNamed:self.url_Image];
    
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    attch.image = currentImage;
    attch.bounds = CGRectMake(-11.5, -2, attch.image.size.width, attch.image.size.height);
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString attributedStringWithAttachment:attch] mutableCopy];
    NSDictionary *attrDict= @{NSForegroundColorAttributeName:UIColorFromHex(0x232323),NSFontAttributeName:[UIFont systemFontOfSize:15]};
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:self.title attributes:attrDict];
    [attrStr appendAttributedString:attri];
    self.titleLabel.attributedText = attrStr;
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
}


@end
